package com.sps.loadingdemo;

/**
 * Created by LZH on 2017/3/27.
 */

import android.content.Context;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

/**
 * 订单管理
 */

public class OrderAdapter extends RecyclerView.Adapter<OrderAdapter.MyViewHolder> {


    List<OrderBean.ObjectBean> objectBeanList;
    Context mContext;

    public OrderAdapter(Context context, List<OrderBean.ObjectBean> objectBeanList) {
        this.mContext = context;
        this.objectBeanList = objectBeanList;

    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.recyclerview_order_item, null);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    //绑定数据
    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        String imagePath = objectBeanList.get(position).getGoods_thumb();
        OrderBean.ObjectBean objectBean = objectBeanList.get(position);
        //显示图片
        Glide.with(mContext).load(GlobalConstant.BASE_URL+imagePath).into(holder.iv_order);
        holder.tv_goods_name.setText(objectBean.getGoods_name());
        //优惠价
        holder.tv_discount.setText("￥" + objectBean.getGoods_price() + "");
        //原价
        holder.tv_original_price.setText("￥" + objectBean.getMarket_price() + "");
        //原价设置中间横线和抗锯齿
        holder.tv_original_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中间横线
        holder.tv_original_price.getPaint().setAntiAlias(true);// 抗锯齿
        //订单状态
        int status = objectBean.getOrder_status();
        if (status == 0) {

            holder.tv_order_status.setText("未确认");

        } else if (status == 1) {
            holder.tv_order_status.setText("已确认");

        } else if (status == 2) {

            holder.tv_order_status.setText("已取消");

        } else if (status == 3) {
            holder.tv_order_status.setText("无效");

        } else {
            holder.tv_order_status.setText("退货");

        }

         int num=objectBean.getGoods_number();
         //数量
         holder.tv_goods_num.setText("x"+num+"");
         //总共多少件商品
         holder.tv_goods_total.setText("共"+num+"件商品");
         //总价
         holder.tv_goods_amounts.setText("合计：￥"+objectBean.getGoods_price()*num+"(含运费￥0.00)");

    }

    @Override
    public int getItemCount() {
        return objectBeanList.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView iv_order;
        TextView tv_goods_name, tv_goods_color, tv_discount, tv_original_price, tv_order_status, tv_goods_num,
                tv_goods_total, tv_goods_amounts;

        public MyViewHolder(View itemView) {
            super(itemView);
            //找到控件
            iv_order = (ImageView) itemView.findViewById(R.id.iv_order);
            tv_goods_name = (TextView) itemView.findViewById(R.id.tv_goods_name);
            tv_goods_color = (TextView) itemView.findViewById(R.id.tv_goods_color);
            tv_discount = (TextView) itemView.findViewById(R.id.tv_discount);
            tv_original_price = (TextView) itemView.findViewById(R.id.tv_original_price);
            tv_order_status = (TextView) itemView.findViewById(R.id.tv_order_status);
            tv_goods_num = (TextView) itemView.findViewById(R.id.tv_goods_num);
            tv_goods_total = (TextView) itemView.findViewById(R.id.tv_goods_total);
            tv_goods_amounts = (TextView) itemView.findViewById(R.id.tv_goods_amounts);


        }
    }
}
